#!/bin/sh
#
FETCH=1

if [ -f ./common_funcs.sh ]; then
    . ./common_funcs.sh
else
    echo "Cannot function without common_funcs.sh!" || exit 3
fi

function inst_nasm() {
    local nasm_ver="nasm-2.07"
    local nasm_url="http://iweb.dl.sourceforge.net/project/nasm/nasm%20sources/$(echo ${nasm_ver} | cut -d'-' -f2)/${nasm_ver}.tar.gz"

    if [ ${FETCH} -gt 0 ]; then
        if chk_cmd curl; then
            curl -C - -O ${nasm_url}
        elif chk_cmd wget; then
            wget ${nasm_url}
        else
            echo "You must have either curl or wget for this script to work!"
            exit 2
        fi

        bak_dir ${nasm_ver}

        tar -zxf ${nasm_ver}.tar.gz
    fi

    if [ ! ${FETCH} -eq 2 ]; then
        (cd ${nasm_ver} && ./configure && make && sudo make install) || return 1
#       cd .. && sudo rm -d -R ${nasm_ver}
    fi
}

case ${1} in
    fetch)
        FETCH=2
        ;;
    nofetch)
        FETCH=0
        ;;
esac

inst_nasm || exit 1

#EOF
